using CoreProject.IService;
using CoreProject.IRepository;
using CoreProject.Model;

namespace CoreProject.Service
{
  public class MenusService : BaseService<Menu>, IMenusService
  {
    private readonly IMenusRepository _repository;

    public MenusService(IMenusRepository repository) : base(repository)
    {
      this._repository = repository;
    }

        public async Task<bool> DeleteMenu(int id)
        {
           return await _repository.DeleteMenu(id);
        }

        public Task<bool> DeleteMenus(int[] ids)
        {
            return _repository.DeleteMenus(ids);
        }

        public async Task<List<Menu>> GetMenus(int roleID)
    {
      var menus = await _repository.GetMenus();
      var list = from  m in  menus 
                 from a in m.Authorities
                 where a.RoleId == roleID
                 select m;
      return list.ToList();
    }

        public async Task<(List<Menu> list, int count)> GetMenusBypage(string name, int page, int size)
        {
            return await _repository.GetMenusBypage(name, page, size);
        }
    }
}
